package com.tul.exercise.base.operator.egs;


import org.junit.jupiter.api.Test;

import static com.tul.exercise.base.utils.Print.print;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @Description 《java编程思想》第3章 示例5：
 *
 *  测试对象的等价性
 *
 **/
public class eg_04_Equivalence {
    @Test
    public void test() {

        Integer n1 = new Integer(47);
        Integer n2 = new Integer(47);

        // == 比较内存地址是否相同，equal比价内容是否相同
        assertFalse(n1 == n2);
        assertTrue(n1.equals(n2));
    }
    @Test
    public void test2() {
        Value v1 = new Value();
        Value v2 = new Value();
        v1.i = v2.i = 100;

        assertFalse(v1 == v2);

        // 默认的equals不比较内容相等
        assertFalse(v1.equals(v2));
    }
}

class Value{
    int i;
}

class Dog{
    String name;

    void says() {
        print(name);
    }
}
